using System;
using System.Collections.Generic;
using System.Text;
using Csla.Data;

namespace MinaspetroLibrary.NoticiasPack
{
    [Serializable()]
    public class NoticiaChildInfo : Csla.ReadOnlyBase<NoticiaChildInfo>
    {
        #region Business Properties and Methods

        //declare members

        private Guid _id = Guid.NewGuid();

        private String _titulo = String.Empty;

        private String _imagemPrincipal = String.Empty;

        private String _legendaImagem = String.Empty;

        private String _chamada = String.Empty;

        private String _descricao = String.Empty;

        private String _fonte = String.Empty;

        private DateTime _data = DateTime.Now;

        private bool _status = false;

        private bool _destaque = false;

        [System.ComponentModel.DataObjectField(true, true)]
        public Guid Id
        {
            get
            {
                return _id;
            }
        }

        public String Titulo
        {
            get
            {
                return _titulo;
            }
        }

        public String ImagemPrincipal
        {
            get
            {
                return _imagemPrincipal;
            }
        }

        public String ImagemPrincipalString
        {
            get
            {
                if (_imagemPrincipal.Contains("_"))
                    return _imagemPrincipal.Substring(_imagemPrincipal.IndexOf("_") + 1);
                return _imagemPrincipal;
            }
        }

        public String LegendaImagem
        {
            get
            {
                return _legendaImagem;
            }
        }

        public String Chamada
        {
            get
            {
                return _chamada;
            }
        }

        public String Descricao
        {
            get
            {
                return _descricao;
            }
        }

        public String Fonte
        {
            get
            {
                return _fonte;
            }
        }

        public DateTime Data
        {
            get
            {
                return _data;
            }
        }

        public String DataShortString
        {
            get
            {
                return _data.ToString("dd/MM/yyyy");
            }
        }

        public String DataFullString
        {
            get
            {
                return _data.ToString("dd/MM/yyyy HH:mm");
            }
        }

        public bool Status
        {
            get
            {
                return _status;
            }
        }

        public bool Destaque
        {
            get
            {
                return _destaque;
            }
        }

        public String StatusString
        {
            get
            {
                if (_status)
                    return "Liberado";
                return "Bloqueado";
            }
        }

        public String DestaqueString
        {
            get
            {
                if (_destaque)
                    return "Destaque";
                return "";
            }
        }


        protected override object GetIdValue()
        {
            return _id.ToString();
        }

        #endregion //Business Properties and Methods

        #region Authorization Rules
        protected override void AddAuthorizationRules()
        {
            //TODO: Define authorization rules in NoticiaChildInfo

        }

        #endregion //Authorization Rules

        #region Factory Methods
        internal static NoticiaChildInfo GetNoticiaChildInfo(SafeDataReader dr)
        {
            return new NoticiaChildInfo(dr);
        }

        private NoticiaChildInfo(SafeDataReader dr)
        {
            Fetch(dr);
        }
        #endregion //Factory Methods

        #region Data Access

        #region Data Access - Fetch
        private void Fetch(SafeDataReader dr)
        {
            FetchObject(dr);

            //load child object(s)
            FetchChildren(dr);

        }

        private void FetchObject(SafeDataReader dr)
        {
            _id = new Guid(dr["Id"].ToString());
            _titulo = dr.GetString("Titulo");
            _imagemPrincipal = dr.GetString("ImagemPrincipal");
            _legendaImagem = dr.GetString("LegendaImagem");
            _chamada = dr.GetString("Chamada");
            _descricao = dr.GetString("Descricao");
            _fonte = dr.GetString("Fonte");
            _data = dr.GetDateTime("Data");
            _status = dr.GetBoolean("Status");
            _destaque = dr.GetBoolean("Destaque");
        }

        private void FetchChildren(SafeDataReader dr)
        {
        }
        #endregion //Data Access - Fetch
        #endregion //Data Access
    }
}
